<template>
  <div class="app-container">
    <div ref="chart" style="width:80%;height:380px"></div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="出入库" prop="state">
        <el-select v-model="queryParams.state" clearable placeholder="出入库">
          <el-option
            v-for="item in stateList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" type="index"/>
      <el-table-column label="用户名称" align="center" prop="username"/>
      <el-table-column label="合计" align="center" prop="total"/>
      <!--      <el-table-column label="规格" align="center" prop="specification"/>-->
      <!--      <el-table-column label="备注" align="center" prop="remark"/>-->
      <!--      <el-table-column label="入库时间" align="center" width="148" prop="createTime"/>-->
      <el-table-column label="状态" align="center" prop="state" :formatter="FormatterState"/>


    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { selectSumCountGroupByUid } from '@/api/emsboot/order'
import { listWarehouse } from '@/api/emsboot/warehouse'

export default {
  name: 'Order',
  components: {},
  data() {
    return {
      stateList: [
        { id: '0', name: '入库' },
        { id: '1', name: '出库' }
      ],
      // 仓库列表
      warehouseList: [],
      productList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单信息表格数据
      orderList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      AuditDialogVisible: false,
      auditList: [
        {
          id: 0,
          name: '待处理'
        }, {
          id: 1,
          name: '通过'
        }, {
          id: 2,
          name: '不通过'
        }
      ],
      auditform: {
        auditFlag: null
      },
      //拒绝表单
      retakeFrom: {
        des: null,
        oid: null
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pid: null,
        count: null,
        specification: null,
        packaging: null,
        cid: null,
        state: '0'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    // // 仓库列表
    // listWarehouse().then(response => {
    //   this.warehouseList = response.rows
    // })
  },
  methods: {
    getEchartData() {
      const chart = this.$refs.chart
      if (chart) {
        const myChart = this.$Mecharts.init(chart)
        const option = {
          title: {
            text: '客户报表'
          },
          tooltip: {},
          legend: {
            data: ['客户报表']
          },
          xAxis: {
            data: this.orderList.map(item => item.username)
          },
          yAxis: {},
          series: [
            {
              name: '合计',
              type: 'bar',
              data: this.orderList.map(item => item.total),
              color: [
                '#7a225f'
              ]
            }
          ]
        }
        myChart.setOption(option)
        window.addEventListener('resize', function() {
          myChart.resize()
        })
      }
      this.$on('hook:destroyed', () => {
        window.removeEventListener('resize', function() {
          myChart.resize()
        })
      })
    },
    auditClick(item) {
      console.log(item)
    },
    openLoadding() {
      this.loading_const = this.$loading({
        lock: true,
        text: '导入时间较长,请耐心等待。',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
        customClass: 'loading_area'
      })
    },
    FormatterState(row) {
      for (let i = 0; i < this.stateList.length; i++) {
        if (this.stateList[i].id == row.state) {
          return this.stateList[i].name
        }
      }
    },
    /** 查询订单信息列表 */
    getList() {
      this.loading = true
      // listProduct().then(response => {
      //   this.productList = response.rows
      //
      // })

      selectSumCountGroupByUid(this.queryParams).then(response => {
        this.orderList = response.rows
        this.total = response.total
        this.loading = false
        this.getEchartData()
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pid: null,
        count: null,
        specification: null,
        packaging: null,
        cid: null,
        state: '0'
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    }

  }
}
</script>
